-
Notifications
You must be signed in to change notification settings - Fork 439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
issue #934: multi-thread compaction support #976
base: master
Are you sure you want to change the base?
Conversation
build |
9c789c6
to
b38af4b
Compare
4ee16ed
to
d84e0b7
Compare
// check filesystem, and then check pending_outputs_ | ||
std::vector<std::string> filenames; | ||
mutex_.Unlock(); | ||
env_->GetChildren(dbname_, &filenames); // Ignoring errors on purpose |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why Ignoring errors on purpose
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
即使本次删除旧sst失败,下一次compact也会继续删除,所以没有必要因为此处失败,而认为本次compact失败,compact重做的话,io开销很重。
f28504a
to
e61e91b
Compare
src/leveldb/db/db_table.cc
Outdated
@@ -219,10 +219,10 @@ Status DBTable::Init() { | |||
std::vector<uint64_t> snapshot_sequence = options_.snapshots_sequence; | |||
std::map<uint64_t, uint64_t> rollbacks = options_.rollbacks; | |||
for (std::set<uint32_t>::iterator it = options_.exist_lg_list->begin(); | |||
it != options_.exist_lg_list->end() && s.ok(); ++it) { | |||
it != options_.exist_lg_list->end() && s.ok(); ++it) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
改这个缩进是基于一种怎样的考虑?
59b896b
to
1741aa5
Compare
@baidu/tera_dev 请都瞧一瞧。 LGTM |
1741aa5
to
bc1ff22
Compare
build |
1 similar comment
build |
bc1ff22
to
8585854
Compare
src/leveldb/db/db_impl.h
Outdated
const InternalKey* begin; // NULL means beginning of key range | ||
const InternalKey* end; // NULL means end of key range | ||
InternalKey tmp_storage; // Used to keep track of compaction progress | ||
int compaction_conflict; // 0 == idle, 1 == conflict, 2 == wake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
直接用ManualCompactState?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
enum内部也是个int吧
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
只是感觉这样好读
commit log里,multithread中间加个-,compactiong拼错了 |
5ec0c93
to
549443c
Compare
已修改 |
549443c
to
58cb9cf
Compare
build |
58cb9cf
to
691adcf
Compare
build |
2 similar comments
build |
build |
691adcf
to
0dc050b
Compare
在看ing,需要点时间。。稍安勿躁! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
求补点注释:)
} | ||
imm_->SetBeingFlushed(true); | ||
|
||
if (imm_->ApproximateMemoryUsage() <= 0) { // imm is empty, do nothing |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是什么情况?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
代码完整性检查:memtablet没有数据时,不做内存的dump
src/leveldb/db/db_impl.h
Outdated
struct CompactionTask { | ||
int64_t id; | ||
double score; | ||
uint64_t timeout; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
求注释下各个字段的基本含义
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改
@@ -110,19 +116,19 @@ class DBImpl : public DB { | |||
|
|||
// Compact the in-memory write buffer to disk. Switches to a new | |||
// log-file/memtable and writes a new descriptor iff successful. | |||
Status CompactMemTable() | |||
Status CompactMemTable(bool* sched_idle = NULL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数的参数求注释啊,下同
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
描述改函数是否真正干活,避免空调度
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
防止空调度
src/leveldb/db/db_impl.cc
Outdated
// end of tera-specific | ||
|
||
bool ScoreSortDesc(std::pair<double, uint64_t> i, std::pair<double, uint64_t> j) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
函数名求不要简写,看不懂。。。
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改
src/leveldb/db/db_impl.cc
Outdated
c->ReleaseInputs(); | ||
DeleteObsoleteFiles(); | ||
DeleteObsoleteFiles();// delete any sst not in version set. if comapct and flush mem handle in multi-thread, may delete new data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个注释啥意思?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同问?
|
||
// Information for a manual compaction | ||
enum ManualCompactState { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
跪求注释,这几种状态的定义
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
缺少单测吧?
src/leveldb/db/db_impl.h
Outdated
uint64_t bg_compaction_timeout_; | ||
int64_t bg_schedule_id_; | ||
std::vector<CompactionTask*> bg_compaction_tasks_; | ||
int bg_compaction_scheduled_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bg_compaction_scheduled_不需要了吧? bg_compaction_score_可以计算出来?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改
src/leveldb/db/db_impl.h
Outdated
std::vector<CompactionTask*> bg_compaction_tasks_; | ||
int bg_compaction_scheduled_; | ||
std::vector<double> bg_compaction_score_; | ||
std::vector<int64_t> bg_schedule_id_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bg_compaction_score_和bg_schedule_id_ 放在一个结构体里?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
score和id不是同时产生的,没有必要放到同一个结构体里面
const InternalKey* begin; // NULL means beginning of key range | ||
const InternalKey* end; // NULL means end of key range | ||
InternalKey tmp_storage; // Used to keep track of compaction progress | ||
ManualCompactState compaction_conflict; // 0 == idle, 1 == conflict, 2 == wake |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compaction_conflict变量命名有点奇怪? 猜不出什么含义?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
就是手动compact并发冲突
@@ -79,6 +79,13 @@ class MemTable { | |||
empty_ = false; | |||
} | |||
|
|||
bool BeingFlushed() { return being_flushed_;} | |||
void SetBeingFlushed(bool flag) { | |||
assert(flag ? !being_flushed_ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
为什么要加assert?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
放置后续同学改次块代码改错
@@ -314,6 +314,14 @@ struct Options { | |||
// Default: 10 % | |||
uint64_t del_percentage; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注释中的default值是10, 然而实际的default值是20
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改
src/leveldb/db/db_impl.cc
Outdated
@@ -746,13 +772,19 @@ Status DBImpl::CompactMemTable() { | |||
Log(options_.info_log, "[%s] CompactMemTable SetLastSequence %lu", | |||
dbname_.c_str(), edit.GetLastSequence()); | |||
s = versions_->LogAndApply(&edit, &mutex_); | |||
pending_outputs_.erase(number); | |||
} else { | |||
// TODO: dump memtable error, delete temp file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
把TODO补上逻辑还是不需要TODO?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已改
src/leveldb/db/db_impl.cc
Outdated
MutexLock lock(&mutex_); | ||
Status s; | ||
if (recover_mem_ == NULL) { | ||
DeleteObsoleteFiles(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
recover阶段需要增加这步吗?
src/leveldb/db/db_impl.cc
Outdated
} | ||
|
||
bg_compaction_scheduled_ = false; | ||
bg_compaction_scheduled_--; | ||
std::vector<CompactionTask*>::iterator task_id = std::find(bg_compaction_tasks_.begin(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
是代码格式乱了, 还是显示的乱了?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
显示问题
src/leveldb/db/db_impl.cc
Outdated
c->ReleaseInputs(); | ||
DeleteObsoleteFiles(); | ||
DeleteObsoleteFiles();// delete any sst not in version set. if comapct and flush mem handle in multi-thread, may delete new data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同问?
@@ -1118,6 +1216,7 @@ void DBImpl::CleanupCompaction(CompactionState* compact) { | |||
for (size_t i = 0; i < compact->outputs.size(); i++) { | |||
const CompactionState::Output& out = compact->outputs[i]; | |||
pending_outputs_.erase(BuildFullFileNumber(dbname_, out.number)); | |||
Log(options_.info_log, "[%s] erase pending_output #%lu", dbname_.c_str(), out.number); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
日志里最好都写filename, 便于追查问题, 另外这个日志会不会输出量较大?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
追查问题就是用sst number
db_test里面基本能覆盖多线程compact的测试 |
LGTM |
17702ce
to
b45434e
Compare
#934 compact优化,story3, 多线程compact